/*
 * @Descripttion: 文件说明
 * @version: 0.0.1
 * @Author: pengshuai
 * @Date: 2023-11-01 10:39:22
 * @LastEditors: PengShuai
 * @LastEditTime: 2023-11-02 10:33:28
 */
import axios from 'axios'
// 创建axios实例
const service = axios.create({
  timeout: 300 * 1000, // ms请求超时时间
})
 
// request拦截器
service.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    // Do something with request error
    Promise.reject(error)
  }
)
 
// respone拦截器
service.interceptors.response.use(
  (response) => {
    const res = response
    if (res.status !== 200) {
      return Promise.reject(response)
    } else {
      if (res.status === 200) {
        return res.data
      } else {
        return Promise.reject(res.data.message)
      }
    }
  },
  (error) => {
    return Promise.reject(error)
  }
)
 
export default service
 